One of my clients has had a long standing requirement to render all of their pages under the .htm extension rather than .php or even no extension at all. This requires a change to the server configuration to tell it to parse .htm files as php.
Rendering .htm files as php
The standard answer across the web is to add the following handler to the .htaccess file of the server:
AddType application/x-httpd-php .htm
However, since WHM / CPanel started to use EasyApache4 this has been changed to include your php version as follows:
AddHandler application/x-httpd-ea-php54 .php .php5 .htm
(Assuming you are using php 5.4)
Getting this wrong has severe consequences in that if your server does not know to render the .htm file as php the browser will either show the php code as plain text or it will download the page with all the code included in it.
UPCP Job updated the .htaccess file
This all worked fine for a long long time, until recently the daily upcp job responsible for updating CPanel auto updated the .htaccess file. This changed the line to:
AddHandler application/x-httpd-ea-php54 .php .php5
Stripping out my .htm extension and as a result rendering php code in the browser. While this was an easy fix I set about trying to understand what had happened.
The code was surrounded by a comment which stated: php — BEGIN cPanel-generated handler, do not edit. Big clue… so if it is no longer a direct .htaccess update, what sets it? The answer was pretty straight forward:
Go to CPanel, under advanced click Apache Handlers.
Under User Defined Apache Handlers there should be an entry with something like the following:
Handler: application/x-httpd-ea-php54
Extension(s): .php .php5 .phtml .htm
If it’s not there use the form above that section to add it.
In my case, this already existed, but I’ve since found out that it was being interpreted from the .htaccess which was updated manually. You need to re-add the handler for it to take effect and then after any system update to the .htaccess, it will replace the extensions as required.